from PySide import QtGui
from PySide.QtCore import Qt
import time
import pickle
import b_data
import g_fileio
import g_menubar
import g_layout
import g_editnodes
import g_editmembers
import g_editmaterials
import g_editloads
import g_editfields
import g_editboundaries
import g_editsettings

class MainWindow(QtGui.QMainWindow):

	def __init__(self):
		super(MainWindow, self).__init__()
		self.initProgram()
		self.initUI()
		self.count = 0;
	
	def initProgram(self):
		self.data = b_data.Data(2)
		self.fileio = g_fileio.FileIO(self)
	
	def initUI(self):
		self.statusBar().showMessage("And so it begins...")
		self.setGeometry(20, 20, 600, 400)
		self.setWindowTitle(self.fileio.makeWindowTitle())
		self.setWindowIcon(QtGui.QIcon('tensile-structures.png'))
		self.layout = g_layout.Layout(self)
		self.editnodes = g_editnodes.EditNodes(self)
		self.editmembers = g_editmembers.EditMembers(self)
		self.editmaterials = g_editmaterials.EditMaterials(self)
		self.editloads = g_editloads.EditLoads(self)
		self.editfields = g_editfields.EditFields(self)
		self.editboundaries = g_editboundaries.EditBoundaries(self)
		self.editsettings = g_editsettings.EditSettings(self)
		self.setCentralWidget(self.layout)
		g_menubar.MenuBar(self)
		self.show()
	
	def addMember(self, member):
		pass
		
	def removeMember(self, member):
		pass
	
	def updateMember(self, member):
		self.layout.view.updateMember(member)
	
	def addNode(self, node):
		pass
	
	def removeNode(self, node):
		pass
	
	def updateNode(self, node):
		self.layout.view.updateNode(node)
	
	def updateAll(self, check=None):
		self.editnodes.updateNodes(check)
		self.editmembers.updateMembers(check)
		self.editmaterials.updateMaterials(check)
		#self.editloads.updateLoads(check)
		self.editfields.updateFields(check)
		#self.editboundaries.updateBoundaries(check)
		self.layout.updateView()
		
	def closeEvent(self, event):
		"""
		if self.fileio.saved:
			reply = QtGui.QMessageBox.question(self, 'Exit Dialog', "Leaving so soon?\n\nAre you sure you want to quit?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
		else:
			reply = QtGui.QMessageBox.question(self, 'Exit Dialog', "Save changes before quitting?\n\nI'd hate to see you lose your work.", QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save)
		if reply == QtGui.QMessageBox.Save:
			event.accept()
			self.fileio.fileSave()
		elif reply == QtGui.QMessageBox.Discard or reply == QtGui.QMessageBox.Yes:
			event.accept()
		else:
			event.ignore()
		"""
		del self.editnodes
		del self.editmembers
		del self.editmaterials
		#del self.editloads
		del self.editfields
		#del self.editboundaries
		del self.editsettings
		event.accept()
